
#include "pr2000_support.h"
#if defined(__HOST_LINUX_SYSTEM__)
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/miscdevice.h>
#include <linux/proc_fs.h>
#include <linux/kthread.h>
#include <linux/freezer.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/system.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/string.h>
#include <linux/list.h>
#include <asm/delay.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/poll.h>
#include <asm/bitops.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <linux/moduleparam.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
#elif defined(__HOST_MICOM_SYSTEM__)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(STM32F10X_HD)
#include "stm32f10x.h"
#else
//#include "stm8s.h"
#endif

//#include "uart.h"
//#include "delay.h"
//#include "user_func.h"
#endif
#include "pr2000.h"
#include "pr2000_table.h"
#include "pr2000_func.h"
#include "pr2000_user_config.h"
#include "pr2000_ceqfunc.h"
#include "typedef.h"
#ifdef SUPPORT_CEQ
#define PR2000_CEQ_EST_COMP(x,y)        ((0x9600*x)/y)
int PR2000_GetDetGainStatus(const int i2cFd, const uint8_t slvAddr,
                            _stPR2000_DetGainStatus*pstDetGainStatus)
{
    int result = -1;
    _stPR2000_Reg stReg;
    uint8_t u8RegData;
    if(pstDetGainStatus == NULL)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x61\x72\x67\x75" "\n");
        return(result);
    }
    stReg.
    reg = 0x0003;
    u8RegData = 0;
    if((result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page,
                                 stReg.b.addr, &u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x72\x65\x61\x64" "\n");
        return(result);
    }
    pstDetGainStatus->syncLevel = u8RegData;
    stReg.reg = 0x0004;
    u8RegData
        = 0;
    if((result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &u8RegData
                                )) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x72\x65\x61\x64" "\n");
        return(result);
    }
    pstDetGainStatus->dcGain = (uint16_t)u8RegData << 8;
    stReg.reg = 0x0005
                ;
    u8RegData = 0;
    if((result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr,
                                 &u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x72\x65\x61\x64" "\n");
        return(result);
    }
    pstDetGainStatus->dcGain |= (uint16_t)u8RegData;
    stReg.reg = 0x0006;
    u8RegData = 0;
    if((result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &
                                 u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x72\x65\x61\x64" "\n");
        return(result);
    }
    pstDetGainStatus->acGain = (uint16_t)u8RegData << 8;
    stReg.reg = 0x0007
                ;
    u8RegData = 0;
    if((result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr,
                                 &u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x72\x65\x61\x64" "\n");
        return(result);
    }
    pstDetGainStatus->acGain |= (uint16_t)u8RegData;
    stReg.reg = 0x0008;
    u8RegData = 0;
    if((result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &
                                 u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x72\x65\x61\x64" "\n");
        return(result);
    }
    pstDetGainStatus->comp1 = (uint16_t)u8RegData << 8;
    stReg.reg = 0x0009;
    u8RegData = 0;
    if((result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &
                                 u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x72\x65\x61\x64" "\n");
        return(result);
    }
    pstDetGainStatus->comp1 |= (uint16_t)u8RegData;
    stReg.reg = 0x000a;
    u8RegData = 0;
    if((result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &
                                 u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x72\x65\x61\x64" "\n");
        return(result);
    }
    pstDetGainStatus->comp2 = (uint16_t)u8RegData << 8;
    stReg.reg = 0x000b;
    u8RegData = 0;
    if((result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &
                                 u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x72\x65\x61\x64" "\n");
        return(result);
    }
    pstDetGainStatus->comp2 |= (uint16_t)u8RegData;
    stReg.reg = 0x000c;
    u8RegData = 0;
    if((result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &
                                 u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x72\x65\x61\x64" "\n");
        return(result);
    }
    pstDetGainStatus->atten1 = (uint16_t)u8RegData << 8;
    stReg.reg = 0x000d
                ;
    u8RegData = 0;
    if((result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr,
                                 &u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x72\x65\x61\x64" "\n");
        return(result);
    }
    pstDetGainStatus->atten1 |= (uint16_t)u8RegData;
    stReg.reg = 0x000e;
    u8RegData = 0;
    if((result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, &
                                 u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x72\x65\x61\x64" "\n");
        return(result);
    }
    pstDetGainStatus->atten2 = (uint16_t)u8RegData << 8;
    stReg.reg = 0x000f
                ;
    u8RegData = 0;
    if((result = PR2000_PageRead(i2cFd, slvAddr, stReg.b.page, stReg.b.addr,
                                 &u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x72\x65\x61\x64" "\n");
        return(result);
    }
    pstDetGainStatus->atten2 |= (uint16_t)u8RegData;
    Dbg(
        "\x25\x78\x2d\x52\x65\x61\x64\x5b\x73\x79\x6e\x63\x4c\x65\x76\x65\x6c\x3a\x25\x30\x32\x78\x2c\x20\x64\x63\x3a\x25\x30\x34\x78\x2c\x20\x61\x63\x3a\x25\x30\x34\x78\x2c\x20\x63\x6f\x6d\x70\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x2c\x20\x61\x74\x74\x65\x6e\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x5d" "\n"
        , slvAddr COMMA pstDetGainStatus->syncLevel COMMA pstDetGainStatus->dcGain COMMA
        pstDetGainStatus->acGain COMMA pstDetGainStatus->comp1 COMMA pstDetGainStatus->
        comp2 COMMA pstDetGainStatus->atten1 COMMA pstDetGainStatus->atten2);
    return(
              result);
}
int PR2000_GetEQGain(const int i2cFd, const uint8_t slvAddr,
                     _stPR2000_VidStatusReg*pstVidStatusReg, const _stPR2000_DetGainStatus*
                     pstDetGainStatus, _stPR2000_MeasureEqInfo*pstMeasureEqInfo)
{
    int result = -1;
    enum
    _eCameraStandard cameraStandard;
    enum _eCameraResolution cameraResolution;
    enum
    _eVideoResolution videoResolution;
    int reJudge = 0;
    uint8_t step = 0;
    int tblReolution =
        0;
    _stPR2000_Table_CEQ_SDResolution*pTblCeqSDComp = NULL, *pTblCeqSDAtten = NULL;
    _stPR2000_Table_CEQ_STD_HDResolution*pTblCeqHDComp = NULL, *pTblCeqHDAtten = NULL;
    uint8_t vadcEqBandComp = 0, vadcEqBandAtten = 0;
    uint16_t distComp = 0, distAtten = 0;
    uint8_t eqStepCompNum = 0, eqStepAttenNum = 0;
    uint16_t u16Comp = 0;
    if((pstVidStatusReg
        == NULL) || (pstDetGainStatus == NULL) || (pstMeasureEqInfo == NULL))
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x61\x72\x67\x75" "\n");
        return(result);
    }
    if(!
       DEFAULT_AUTODETECT_ENABLE)
    {
        PR2000_ReadStdResol(i2cFd, slvAddr, pstVidStatusReg, &
                            cameraStandard, &cameraResolution, &videoResolution);
        Dbg(
            "\x25\x78\x2d\x46\x69\x78\x20\x45\x51\x20\x5b\x43\x61\x6d\x65\x72\x61\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x63\x61\x6d\x65\x72\x61\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x76\x69\x64\x65\x6f\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x5d" "\n"
            , slvAddr COMMA cameraStandard COMMA _strCameraStandard[cameraStandard]COMMA
            cameraResolution COMMA _strCameraResolution[cameraResolution]COMMA
            videoResolution COMMA _strVideoResolution[videoResolution]);
    }
    else
    {
        PR2000_GetStdResol(i2cFd, slvAddr, pstVidStatusReg, &cameraStandard, &
                           cameraResolution, &videoResolution, &reJudge);
        Dbg(
            "\x25\x78\x2d\x45\x51\x20\x5b\x43\x61\x6d\x65\x72\x61\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x63\x61\x6d\x65\x72\x61\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x76\x69\x64\x65\x6f\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x5d" "\n"
            , slvAddr COMMA cameraStandard COMMA _strCameraStandard[cameraStandard]COMMA
            cameraResolution COMMA _strCameraResolution[cameraResolution]COMMA
            videoResolution COMMA _strVideoResolution[videoResolution]);
    }
    switch(
        cameraStandard)
    {
        case SD:
        {
            pTblCeqSDComp = (_stPR2000_Table_CEQ_SDResolution*)
                            pr2000_ceq_table_estComplex_SD;
            pTblCeqSDAtten = (_stPR2000_Table_CEQ_SDResolution*
                             )pr2000_ceq_table_estAtten2_SD;
            if(cameraResolution == camera_ntsc)
            {
                tblReolution = 0;
            }
            else
            {
                tblReolution = 1;
            }
        }
        break;
#if defined(SUPPORT_STD_PVI)
        case PVI:
        {
            pTblCeqHDComp = (_stPR2000_Table_CEQ_STD_HDResolution*)
                            pr2000_ceq_std_table_estComplex_PVI;
            pTblCeqHDAtten = (
                                 _stPR2000_Table_CEQ_STD_HDResolution*)pr2000_ceq_std_table_estAtten2_PVI;
            tblReolution = cameraResolution - camera_1280x720p60;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
            if(cameraResolution >= camera_1280x800p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x800p60;
            }
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
            if(cameraResolution >= camera_1280x960p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x960p60;
            }
#endif
        }
        break;
#endif
#if defined(SUPPORT_STD_HDA)
        case HDA:
        {
            pTblCeqHDComp = (_stPR2000_Table_CEQ_STD_HDResolution*)
                            pr2000_ceq_std_table_estComplex_HDA;
            pTblCeqHDAtten = (
                                 _stPR2000_Table_CEQ_STD_HDResolution*)pr2000_ceq_std_table_estAtten2_HDA;
            tblReolution = cameraResolution - camera_1280x720p60;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
            if(cameraResolution >= camera_1280x800p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x800p60;
            }
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
            if(cameraResolution >= camera_1280x960p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x960p60;
            }
#endif
        }
        break;
#endif
#if defined(SUPPORT_STD_CVI)
        case CVI:
        {
            pTblCeqHDComp = (_stPR2000_Table_CEQ_STD_HDResolution*)
                            pr2000_ceq_std_table_estComplex_CVI;
            pTblCeqHDAtten = (
                                 _stPR2000_Table_CEQ_STD_HDResolution*)pr2000_ceq_std_table_estAtten2_CVI;
            tblReolution = cameraResolution - camera_1280x720p60;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
            if(cameraResolution >= camera_1280x800p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x800p60;
            }
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
            if(cameraResolution >= camera_1280x960p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x960p60;
            }
#endif
        }
        break;
#endif
#if defined(SUPPORT_STD_HDT)
        case HDT_OLD:
        {
            pTblCeqHDComp = (_stPR2000_Table_CEQ_STD_HDResolution*)
                            pr2000_ceq_std_table_estComplex_HDT_OLD;
            pTblCeqHDAtten = (
                                 _stPR2000_Table_CEQ_STD_HDResolution*)pr2000_ceq_std_table_estAtten2_HDT_OLD;
            tblReolution = cameraResolution - camera_1280x720p60;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
            if(cameraResolution >= camera_1280x800p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x800p60;
            }
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
            if(cameraResolution >= camera_1280x960p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x960p60;
            }
#endif
        }
        break;
        case HDT_NEW:
        {
            pTblCeqHDComp = (_stPR2000_Table_CEQ_STD_HDResolution*)
                            pr2000_ceq_std_table_estComplex_HDT_NEW;
            pTblCeqHDAtten = (
                                 _stPR2000_Table_CEQ_STD_HDResolution*)pr2000_ceq_std_table_estAtten2_HDT_NEW;
            tblReolution = cameraResolution - camera_1280x720p60;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
            if(cameraResolution >= camera_1280x800p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x800p60;
            }
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
            if(cameraResolution >= camera_1280x960p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x960p60;
            }
#endif
        }
        break;
#endif
        default:
        {
            result = -1;
            Error(
                "\x49\x6e\x76\x61\x6c\x69\x64\x20\x63\x61\x6d\x65\x72\x61\x20\x53\x74\x61\x6e\x64\x61\x72\x64\x28\x25\x64\x29" "\n"
                , cameraStandard);
            return(result);
        }
    }
    if(pstDetGainStatus->comp2 != 0)
    {
        u16Comp =
            PR2000_CEQ_EST_COMP(pstDetGainStatus->comp1, pstDetGainStatus->comp2);
    }
    Dbg(
        "\x25\x78\x2d\x47\x65\x74\x20\x6d\x65\x61\x73\x75\x72\x65\x20\x43\x6f\x6d\x70\x3a\x30\x78\x25\x78\x28\x25\x78\x2f\x25\x78\x29" "\n"
        , slvAddr COMMA u16Comp COMMA pstDetGainStatus->comp1 COMMA pstDetGainStatus->
        comp2);
    if(cameraStandard == SD)
    {
        if(pTblCeqSDComp[MAX_PR2000_CEQ_COMP_TBL_NUM - 1].pData[tblReolution][1] < u16Comp)
        {
            vadcEqBandComp = pTblCeqSDComp[MAX_PR2000_CEQ_COMP_TBL_NUM - 1].pData[tblReolution]
                             [2];
            distComp = pTblCeqSDComp[MAX_PR2000_CEQ_COMP_TBL_NUM - 1].distance;
            eqStepCompNum =
                0xff;
        }
        else if(pTblCeqSDComp[0].pData[tblReolution][0] > u16Comp)
        {
            vadcEqBandComp = pTblCeqSDComp[0].pData[tblReolution][2];
            distComp = pTblCeqSDComp[0].distance;
            eqStepCompNum = 0;
        }
        else
        {
            for(step = 0; step < MAX_PR2000_CEQ_COMP_TBL_NUM; step++)
            {
                if((pTblCeqSDComp[step
                                 ].pData[tblReolution][0] <= u16Comp) && (u16Comp <= pTblCeqSDComp[step].pData[
                                             tblReolution][1]))
                {
                    vadcEqBandComp = pTblCeqSDComp[step].pData[tblReolution][2];
                    distComp = pTblCeqSDComp[step].distance;
                    eqStepCompNum = step;
                    break;
                }
            }
        }
        if(pTblCeqSDAtten[MAX_PR2000_CEQ_ATTEN_TBL_NUM - 1].pData[tblReolution][1] <
           pstDetGainStatus->atten2)
        {
            vadcEqBandAtten = pTblCeqSDAtten[MAX_PR2000_CEQ_ATTEN_TBL_NUM - 1].pData[
                                  tblReolution][2];
            distAtten = pTblCeqSDAtten[MAX_PR2000_CEQ_ATTEN_TBL_NUM - 1].distance;
            eqStepAttenNum
                = 0xff;
        }
        else if(pTblCeqSDAtten[0].pData[tblReolution][0] > pstDetGainStatus->atten2)
        {
            vadcEqBandAtten = pTblCeqSDAtten[0].pData[tblReolution][2];
            distAtten = pTblCeqSDAtten[0].distance;
            eqStepAttenNum = 0;
        }
        else
        {
            for(step = 0; step < MAX_PR2000_CEQ_ATTEN_TBL_NUM; step++)
            {
                if((pTblCeqSDAtten[
                        step].pData[tblReolution][0] <= pstDetGainStatus->atten2) && (pstDetGainStatus->
                                atten2 <= pTblCeqSDAtten[step].pData[tblReolution][1]))
                {
                    vadcEqBandAtten =
                        pTblCeqSDAtten[step].pData[tblReolution][2];
                    distAtten = pTblCeqSDAtten[step].distance;
                    eqStepAttenNum = step;
                    break;
                }
            }
        }
    }
    else
    {
        if(pTblCeqHDComp[MAX_PR2000_CEQ_COMP_TBL_NUM - 1].pData[tblReolution][1] < u16Comp)
        {
            vadcEqBandComp = pTblCeqHDComp[MAX_PR2000_CEQ_COMP_TBL_NUM - 1].pData[tblReolution]
                             [2];
            distComp = pTblCeqHDComp[MAX_PR2000_CEQ_COMP_TBL_NUM - 1].distance;
            eqStepCompNum =
                0xff;
        }
        else if(pTblCeqHDComp[0].pData[tblReolution][0] > u16Comp)
        {
            vadcEqBandComp = pTblCeqHDComp[0].pData[tblReolution][2];
            distComp = pTblCeqHDComp[0].distance;
            eqStepCompNum = 0;
        }
        else
        {
            for(step = 0; step < MAX_PR2000_CEQ_COMP_TBL_NUM; step++)
            {
                if((pTblCeqHDComp[step
                                 ].pData[tblReolution][0] <= u16Comp) && (u16Comp <= pTblCeqHDComp[step].pData[
                                             tblReolution][1]))
                {
                    vadcEqBandComp = pTblCeqHDComp[step].pData[tblReolution][2];
                    distComp = pTblCeqHDComp[step].distance;
                    eqStepCompNum = step;
                    break;
                }
            }
        }
        if(pTblCeqHDAtten[MAX_PR2000_CEQ_ATTEN_TBL_NUM - 1].pData[tblReolution][1] <
           pstDetGainStatus->atten2)
        {
            vadcEqBandAtten = pTblCeqHDAtten[MAX_PR2000_CEQ_ATTEN_TBL_NUM - 1].pData[
                                  tblReolution][2];
            distAtten = pTblCeqHDAtten[MAX_PR2000_CEQ_ATTEN_TBL_NUM - 1].distance;
            eqStepAttenNum
                = 0xff;
        }
        else if(pTblCeqHDAtten[0].pData[tblReolution][0] > pstDetGainStatus->atten2)
        {
            vadcEqBandAtten = pTblCeqHDAtten[0].pData[tblReolution][2];
            distAtten = pTblCeqHDAtten[0].distance;
            eqStepAttenNum = 0;
        }
        else
        {
            for(step = 0; step < MAX_PR2000_CEQ_ATTEN_TBL_NUM; step++)
            {
                if((pTblCeqHDAtten[
                        step].pData[tblReolution][0] <= pstDetGainStatus->atten2) && (pstDetGainStatus->
                                atten2 <= pTblCeqHDAtten[step].pData[tblReolution][1]))
                {
                    vadcEqBandAtten =
                        pTblCeqHDAtten[step].pData[tblReolution][2];
                    distAtten = pTblCeqHDAtten[step].distance;
                    eqStepAttenNum = step;
                    break;
                }
            }
        }
    }
    pstMeasureEqInfo->vadcEqBandComp = vadcEqBandComp;
    pstMeasureEqInfo->distComp =
        distComp;
    pstMeasureEqInfo->eqStepCompNum = eqStepCompNum;
    pstMeasureEqInfo->
    vadcEqBandAtten = vadcEqBandAtten;
    pstMeasureEqInfo->distAtten = distAtten;
    pstMeasureEqInfo->eqStepAttenNum = eqStepAttenNum;
    if(distComp > 1200)
    {
        pstMeasureEqInfo->bTypeComp = 1;
        pstMeasureEqInfo->vadcEqBand = pstMeasureEqInfo->
                                       vadcEqBandComp;
        pstMeasureEqInfo->dist = pstMeasureEqInfo->distComp;
        pstMeasureEqInfo->eqStepNum = pstMeasureEqInfo->eqStepCompNum;
    }
    else
    {
        pstMeasureEqInfo->bTypeComp = 0;
        pstMeasureEqInfo->vadcEqBand = pstMeasureEqInfo->
                                       vadcEqBandAtten;
        pstMeasureEqInfo->dist = pstMeasureEqInfo->distAtten;
        pstMeasureEqInfo->eqStepNum = pstMeasureEqInfo->eqStepAttenNum;
    }
    result = 0;
    Dbg(
        "\x25\x78\x2d\x47\x65\x74\x20\x43\x6f\x6d\x70\x28\x30\x78\x25\x78\x2f\x25\x64\x6d\x29\x2c\x20\x41\x74\x74\x65\x6e\x28\x30\x78\x25\x78\x2f\x25\x64\x6d\x29\x2c\x20\x72\x65\x73\x75\x6c\x74\x28\x30\x78\x25\x78\x2f\x25\x64\x6d\x29" "\n"
        , slvAddr COMMA pstMeasureEqInfo->vadcEqBandComp COMMA pstMeasureEqInfo->distComp
        COMMA pstMeasureEqInfo->vadcEqBandAtten COMMA pstMeasureEqInfo->distAtten COMMA
        pstMeasureEqInfo->vadcEqBand COMMA pstMeasureEqInfo->dist);
    return(result);
}
int
PR2000_SetEQGain(const int i2cFd, const uint8_t slvAddr, _stPR2000_VidStatusReg*
                 pstVidStatusReg, const _stPR2000_DetGainStatus*pstDetGainStatus,
                 _stPR2000_MeasureEqInfo*pstMeasureEqInfo)
{
    int result = -1;
    _stPR2000_Reg stReg;
    uint8_t u8RegData;
    uint8_t u8RegMask;
    Print(
        "\x25\x78\x2d\x53\x65\x74\x20\x76\x61\x64\x63\x45\x71\x42\x61\x6e\x64\x3a\x30\x78\x25\x78" "\n"
        , slvAddr COMMA pstMeasureEqInfo->vadcEqBand);
    if((pstVidStatusReg == NULL) || (
           pstDetGainStatus == NULL) || (pstMeasureEqInfo == NULL))
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x61\x72\x67\x75" "\n");
        return(result);
    }
    stReg.
    reg = 0x0013;
    u8RegMask = 0x37;
    u8RegData = (pstMeasureEqInfo->vadcEqBand & 0x7) | (((
                    pstMeasureEqInfo->vadcEqBand & 0x18) << 1) & 0x30);
    if((result = PR2000_PageWriteMaskBit(
                     i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
        ;
        return(result);
    }
    result = PR2000_SetVADCGain(i2cFd, slvAddr, pstVidStatusReg,
                                pstDetGainStatus, pstMeasureEqInfo);
    return(result);
}
int PR2000_GetTunnEQGain(
    const int i2cFd, const uint8_t slvAddr, _stPR2000_VidStatusReg*pstVidStatusReg,
    const _stPR2000_DetGainStatus*pstDetGainStatus, const _stPR2000_TunnFactor*
    pstTunnFactor, _stPR2000_MeasureEqInfo*pstMeasureEqInfo)
{
    int result = -1;
    enum
    _eCameraStandard cameraStandard;
    enum _eCameraResolution cameraResolution;
    enum
    _eVideoResolution videoResolution;
    int reJudge = 0;
    int tblReolution = 0;
    _stPR2000_Table_CEQ_SDResolution*pTblCeqSDComp = NULL, *pTblCeqSDAtten = NULL;
    _stPR2000_Table_CEQ_STD_HDResolution*pTblCeqHDComp = NULL, *pTblCeqHDAtten = NULL;
    uint8_t vadcEqBandComp = 0, vadcEqBandAtten;
    uint16_t distComp = 0, distAtten = 0;
    uint8_t
    eqStepCompNum = 0, eqStepAttenNum = 0;
    uint8_t bTypeComp = 0;
    if((pstVidStatusReg == NULL)
       || (pstDetGainStatus == NULL) || (pstTunnFactor == NULL) || (pstMeasureEqInfo == NULL))
    {
        ErrorString("\x69\x6e\x76\x61\x6c\x69\x64\x20\x61\x72\x67\x75" "\n");
        return(
                  result);
    }
    PR2000_GetStdResol(i2cFd, slvAddr, pstVidStatusReg, &cameraStandard, &
                       cameraResolution, &videoResolution, &reJudge);
    Print(
        "\x25\x78\x2d\x54\x75\x6e\x6e\x45\x51\x20\x5b\x43\x61\x6d\x65\x72\x61\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x63\x61\x6d\x65\x72\x61\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x76\x69\x64\x65\x6f\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x5d" "\n"
        , slvAddr COMMA cameraStandard COMMA _strCameraStandard[cameraStandard]COMMA
        cameraResolution COMMA _strCameraResolution[cameraResolution]COMMA
        videoResolution COMMA _strVideoResolution[videoResolution]);
    switch(
        cameraStandard)
    {
        case SD:
        {
            pTblCeqSDComp = (_stPR2000_Table_CEQ_SDResolution*)
                            pr2000_ceq_table_estComplex_SD;
            pTblCeqSDAtten = (_stPR2000_Table_CEQ_SDResolution*
                             )pr2000_ceq_table_estAtten2_SD;
            if(cameraResolution == camera_ntsc)
            {
                tblReolution = 0;
            }
            else
            {
                tblReolution = 1;
            }
        }
        break;
#if defined(SUPPORT_STD_PVI)
        case PVI:
        {
            pTblCeqHDComp = (_stPR2000_Table_CEQ_STD_HDResolution*)
                            pr2000_ceq_std_table_estComplex_PVI;
            pTblCeqHDAtten = (
                                 _stPR2000_Table_CEQ_STD_HDResolution*)pr2000_ceq_std_table_estAtten2_PVI;
            tblReolution = cameraResolution - camera_1280x720p60;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
            if(cameraResolution >= camera_1280x800p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x800p60;
            }
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
            if(cameraResolution >= camera_1280x960p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x960p60;
            }
#endif
        }
        break;
#endif
#if defined(SUPPORT_STD_HDA)
        case HDA:
        {
            pTblCeqHDComp = (_stPR2000_Table_CEQ_STD_HDResolution*)
                            pr2000_ceq_std_table_estComplex_HDA;
            pTblCeqHDAtten = (
                                 _stPR2000_Table_CEQ_STD_HDResolution*)pr2000_ceq_std_table_estAtten2_HDA;
            tblReolution = cameraResolution - camera_1280x720p60;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
            if(cameraResolution >= camera_1280x800p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x800p60;
            }
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
            if(cameraResolution >= camera_1280x960p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x960p60;
            }
#endif
        }
        break;
#endif
#if defined(SUPPORT_STD_CVI)
        case CVI:
        {
            pTblCeqHDComp = (_stPR2000_Table_CEQ_STD_HDResolution*)
                            pr2000_ceq_std_table_estComplex_CVI;
            pTblCeqHDAtten = (
                                 _stPR2000_Table_CEQ_STD_HDResolution*)pr2000_ceq_std_table_estAtten2_CVI;
            tblReolution = cameraResolution - camera_1280x720p60;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
            if(cameraResolution >= camera_1280x800p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x800p60;
            }
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
            if(cameraResolution >= camera_1280x960p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x960p60;
            }
#endif
        }
        break;
#endif
#if defined(SUPPORT_STD_HDT)
        case HDT_OLD:
        {
            pTblCeqHDComp = (_stPR2000_Table_CEQ_STD_HDResolution*)
                            pr2000_ceq_std_table_estComplex_HDT_OLD;
            pTblCeqHDAtten = (
                                 _stPR2000_Table_CEQ_STD_HDResolution*)pr2000_ceq_std_table_estAtten2_HDT_OLD;
            tblReolution = cameraResolution - camera_1280x720p60;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
            if(cameraResolution >= camera_1280x800p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x800p60;
            }
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
            if(cameraResolution >= camera_1280x960p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x960p60;
            }
#endif
        }
        break;
        case HDT_NEW:
        {
            pTblCeqHDComp = (_stPR2000_Table_CEQ_STD_HDResolution*)
                            pr2000_ceq_std_table_estComplex_HDT_NEW;
            pTblCeqHDAtten = (
                                 _stPR2000_Table_CEQ_STD_HDResolution*)pr2000_ceq_std_table_estAtten2_HDT_NEW;
            tblReolution = cameraResolution - camera_1280x720p60;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
            if(cameraResolution >= camera_1280x800p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x800p60;
            }
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
            if(cameraResolution >= camera_1280x960p60)
            {
                tblReolution = cameraResolution -
                               camera_1280x960p60;
            }
#endif
        }
        break;
#endif
        default:
        {
            result = -1;
            Error(
                "\x49\x6e\x76\x61\x6c\x69\x64\x20\x63\x61\x6d\x65\x72\x61\x20\x53\x74\x61\x6e\x64\x61\x72\x64\x28\x25\x64\x29" "\n"
                , cameraStandard);
            return(result);
        }
    }
    eqStepCompNum = pstMeasureEqInfo->eqStepCompNum;
    eqStepAttenNum = pstMeasureEqInfo->eqStepAttenNum;
    distComp = pstMeasureEqInfo->
               distComp;
    distAtten = pstMeasureEqInfo->distAtten;
    bTypeComp = pstMeasureEqInfo->
                bTypeComp;
    if(pstTunnFactor->stepDir > 0)
    {
        if(bTypeComp)
        {
            if(eqStepCompNum < (MAX_PR2000_CEQ_COMP_TBL_NUM - 1))
            {
                eqStepCompNum++
                ;
            }
            else
            {
                return(0);
            }
        }
        else
        {
            if(eqStepAttenNum < (MAX_PR2000_CEQ_ATTEN_TBL_NUM - 1))
            {
                eqStepAttenNum++;
            }
            else
            {
                return(0);
            }
        }
    }
    else
    {
        if(bTypeComp)
        {
            if(eqStepCompNum > 0)
            {
                eqStepCompNum--;
            }
            else
            {
                return(0);
            }
        }
        else
        {
            if(eqStepAttenNum > 0)
            {
                eqStepAttenNum--;
            }
            else
            {
                return(0);
            }
        }
    }
    if(cameraStandard == SD)
    {
        vadcEqBandComp = pTblCeqSDComp[eqStepCompNum].pData[tblReolution][2];
        distComp = pTblCeqSDComp[eqStepCompNum].distance;
        vadcEqBandAtten = pTblCeqSDAtten[eqStepAttenNum].pData[tblReolution][2];
        distAtten = pTblCeqSDAtten[eqStepAttenNum].distance;
    }
    else
    {
        vadcEqBandComp = pTblCeqHDComp[eqStepCompNum].pData[tblReolution][2];
        distComp = pTblCeqHDComp[eqStepCompNum].distance;
        vadcEqBandAtten = pTblCeqHDAtten[eqStepAttenNum].pData[tblReolution][2];
        distAtten = pTblCeqHDAtten[eqStepAttenNum].distance;
    }
    pstMeasureEqInfo->
    vadcEqBandComp = vadcEqBandComp;
    pstMeasureEqInfo->distComp = distComp;
    pstMeasureEqInfo->eqStepCompNum = eqStepCompNum;
    pstMeasureEqInfo->vadcEqBandAtten =
        vadcEqBandAtten;
    pstMeasureEqInfo->distAtten = distAtten;
    pstMeasureEqInfo->
    eqStepAttenNum = eqStepAttenNum;
    if(bTypeComp)
    {
        pstMeasureEqInfo->vadcEqBand =
            pstMeasureEqInfo->vadcEqBandComp;
        pstMeasureEqInfo->dist = pstMeasureEqInfo->
                                 distComp;
        pstMeasureEqInfo->eqStepNum = pstMeasureEqInfo->eqStepCompNum;
    }
    else
    {
        pstMeasureEqInfo->vadcEqBand = pstMeasureEqInfo->vadcEqBandAtten;
        pstMeasureEqInfo
        ->dist = pstMeasureEqInfo->distAtten;
        pstMeasureEqInfo->eqStepNum = pstMeasureEqInfo
                                      ->eqStepAttenNum;
    }
    result = 1;
    Print(
        "\x25\x78\x2d\x54\x75\x6e\x6e\x20\x47\x65\x74\x28\x64\x69\x72\x3a\x25\x64\x2c\x20\x54\x79\x70\x65\x43\x6f\x6d\x70\x3a\x25\x64\x29\x20\x43\x6f\x6d\x70\x28\x30\x78\x25\x78\x2f\x25\x64\x29\x2c\x20\x41\x74\x74\x65\x6e\x28\x30\x78\x25\x78\x2f\x25\x64\x29\x2c\x20\x72\x65\x73\x75\x6c\x74\x28\x30\x78\x25\x78\x2f\x25\x64\x29" "\n"
        , slvAddr COMMA pstTunnFactor->stepDir COMMA pstMeasureEqInfo->bTypeComp COMMA
        pstMeasureEqInfo->vadcEqBandComp COMMA pstMeasureEqInfo->distComp COMMA
        pstMeasureEqInfo->vadcEqBandAtten COMMA pstMeasureEqInfo->distAtten COMMA
        pstMeasureEqInfo->vadcEqBand COMMA pstMeasureEqInfo->dist);
    return(result);
}
int
PR2000_SetVADCGain(const int i2cFd, const uint8_t slvAddr, _stPR2000_VidStatusReg*
                   pstVidStatusReg, const _stPR2000_DetGainStatus*pstDetGainStatus,
                   _stPR2000_MeasureEqInfo*pstMeasureEqInfo)
{
    int result = -1;
    _stPR2000_Reg stReg;
    uint8_t u8RegData;
    uint8_t u8RegMask;
    int reJudge = 0;
    enum _eCameraStandard
    cameraStandard;
    enum _eCameraResolution cameraResolution;
    enum _eVideoResolution
    videoResolution;
    uint16_t dist = 0;
    uint8_t vadcGain = 0;
    uint16_t dcGain = 0;
    uint8_t
    gainfit = 0;
    uint8_t y_out_gain = 0;
    uint8_t step = 0;
    int tblReolution = 0;
    _stPR2000_Table_CEQ_VADC*pTblVadcHD = NULL;
    if((pstVidStatusReg == NULL) || (
           pstDetGainStatus == NULL) || (pstMeasureEqInfo == NULL))
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x61\x72\x67\x75" "\n");
        return(result);
    }
    if(!
       DEFAULT_AUTODETECT_ENABLE)
    {
        PR2000_ReadStdResol(i2cFd, slvAddr, pstVidStatusReg, &
                            cameraStandard, &cameraResolution, &videoResolution);
        Dbg(
            "\x25\x78\x2d\x46\x69\x78\x20\x76\x61\x64\x63\x20\x63\x75\x72\x5b\x43\x61\x6d\x65\x72\x61\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x63\x61\x6d\x65\x72\x61\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x76\x69\x64\x65\x6f\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x20\x72\x65\x4a\x75\x64\x67\x65\x3a\x25\x64\x5d" "\n"
            , slvAddr COMMA cameraStandard COMMA _strCameraStandard[cameraStandard]COMMA
            cameraResolution COMMA _strCameraResolution[cameraResolution]COMMA
            videoResolution COMMA _strVideoResolution[videoResolution]COMMA reJudge);
    }
    else
    {
        PR2000_GetStdResol(i2cFd, slvAddr, pstVidStatusReg, &cameraStandard, &
                           cameraResolution, &videoResolution, &reJudge);
        Dbg(
            "\x25\x78\x2d\x76\x61\x64\x63\x20\x63\x75\x72\x5b\x43\x61\x6d\x65\x72\x61\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x63\x61\x6d\x65\x72\x61\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x76\x69\x64\x65\x6f\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x20\x72\x65\x4a\x75\x64\x67\x65\x3a\x25\x64\x5d" "\n"
            , slvAddr COMMA cameraStandard COMMA _strCameraStandard[cameraStandard]COMMA
            cameraResolution COMMA _strCameraResolution[cameraResolution]COMMA
            videoResolution COMMA _strVideoResolution[videoResolution]COMMA reJudge);
    }
    dcGain
        = pstDetGainStatus->dcGain;
    pTblVadcHD = (_stPR2000_Table_CEQ_VADC*)
                 pr2000_ceq_table_vadc;
    if(cameraResolution > camera_1920x1080p25)
    {
        tblReolution =
            camera_1920x1080p25;
    }
    else
    {
        tblReolution = cameraResolution;
    }
    Dbg(
        "\x25\x78\x2d\x74\x62\x6c\x52\x65\x6f\x6c\x75\x74\x69\x6f\x6e\x28\x25\x64\x29" "\n"
        , slvAddr COMMA tblReolution);
    Dbg(
        "\x25\x78\x2d\x64\x69\x73\x74\x43\x6f\x6d\x70\x3a\x25\x64" "\n", slvAddr COMMA
        pstMeasureEqInfo->distComp);
    if((pstMeasureEqInfo->distComp > 1200))
    {
        dist =
            pstMeasureEqInfo->distComp;
        Dbg(
            "\x25\x78\x2d\x64\x69\x73\x74\x28\x63\x6f\x6d\x70\x29\x25\x64" "\n", slvAddr
            COMMA dist);
        for(step = 0; step < MAX_PR2000_CEQ_VADC_TBL_NUM - 1; step++)
        {
            Dbg(
                "\x25\x78\x2d\x64\x69\x73\x74\x28\x25\x64\x29\x20\x73\x74\x65\x70\x25\x64\x5b\x25\x64\x2d\x25\x64\x5d" "\n"
                , slvAddr COMMA dist COMMA step COMMA pTblVadcHD[step].distance COMMA pTblVadcHD[
                    step].distance);
            if((pTblVadcHD[step].distance <= dist) && (dist < pTblVadcHD[step + 1].
                    distance))
            {
                vadcGain = pTblVadcHD[step].pData[tblReolution][0] & 0xff;
                gainfit = (
                              pTblVadcHD[step].pData[tblReolution][1] >> 8) & 0xff;
                y_out_gain = pTblVadcHD[step].
                             pData[tblReolution][1] & 0xff;
                Dbg(
                    "\x25\x78\x2d\x66\x69\x6e\x64\x20\x76\x61\x64\x63\x20\x70\x61\x72\x61\x6d\x20\x76\x61\x64\x63\x47\x61\x69\x6e\x3a\x25\x30\x32\x78" "\n"
                    , slvAddr COMMA vadcGain);
                break;
            }
        }
    }
    else
    {
        dist = pstMeasureEqInfo->distAtten;
        Dbg(
            "\x25\x78\x2d\x64\x69\x73\x74\x28\x61\x74\x74\x65\x6e\x29\x25\x64" "\n", slvAddr
            COMMA dist);
        for(step = 0; step < MAX_PR2000_CEQ_VADC_TBL_NUM - 1; step++)
        {
            Dbg(
                "\x25\x78\x2d\x64\x69\x73\x74\x28\x25\x64\x29\x20\x73\x74\x65\x70\x25\x64\x5b\x25\x64\x2d\x25\x64\x5d" "\n"
                , slvAddr COMMA dist COMMA step COMMA pTblVadcHD[step].distance COMMA pTblVadcHD[
                    step].distance);
            if((pTblVadcHD[step].distance <= dist) && (dist < pTblVadcHD[step + 1].
                    distance))
            {
                if(dcGain <= 0x2e00)
                {
                    vadcGain = pTblVadcHD[step].pData[tblReolution][0] &
                               0xff;
                }
                else
                {
                    vadcGain = (pTblVadcHD[step].pData[tblReolution][0] >> 8) & 0xff;
                }
                gainfit = (
                              pTblVadcHD[step].pData[tblReolution][1] >> 8) & 0xff;
                y_out_gain = pTblVadcHD[step].
                             pData[tblReolution][1] & 0xff;
                Dbg(
                    "\x25\x78\x2d\x66\x69\x6e\x64\x20\x76\x61\x64\x63\x20\x70\x61\x72\x61\x6d\x20\x76\x61\x64\x63\x47\x61\x69\x6e\x3a\x25\x30\x32\x78" "\n"
                    , slvAddr COMMA vadcGain);
                break;
            }
        }
    }
    pstMeasureEqInfo->vadcGain = vadcGain;
    Print(
        "\x25\x78\x2d\x53\x65\x74\x20\x56\x61\x64\x63\x3a\x30\x78\x25\x78\x28\x64\x65\x74\x44\x63\x67\x61\x69\x6e\x3a\x30\x78\x25\x30\x34\x78\x29\x5d" "\n"
        , slvAddr COMMA vadcGain COMMA dcGain);
    stReg.reg = 0x0011;
    u8RegMask = 0x70;
    u8RegData =
        (pstMeasureEqInfo->vadcGain & 0x7) << 4;
    if((result = PR2000_PageWriteMaskBit(i2cFd,
                                         slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
        ;
        return(result);
    }
    if(cameraStandard == CVI)
    {
        Print(
            "\x25\x78\x2d\x53\x70\x65\x63\x69\x61\x6c\x20\x43\x56\x49\x20\x6d\x6f\x64\x65\x2e\x20\x67\x61\x69\x6e\x66\x69\x74\x3a\x30\x78\x25\x30\x32\x78\x2c\x20\x79\x6f\x75\x74\x67\x61\x69\x6e\x3a\x30\x78\x25\x30\x32\x78" "\n"
            , slvAddr COMMA gainfit COMMA y_out_gain);
        stReg.reg = 0x0101;
        u8RegData = gainfit;
        if((
               result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
        {
            ErrorString(
                "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
            ;
            return(result);
        }
        stReg.reg = 0x0128;
        u8RegData = y_out_gain;
        if((result =
                PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
        {
            ErrorString(
                "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
            ;
            return(result);
        }
    }
    return(result);
}
int PR2000_SetTunnVADCGain(const int i2cFd,
                           const uint8_t slvAddr, _stPR2000_VidStatusReg*pstVidStatusReg, const
                           _stPR2000_DetGainStatus*pstDetGainStatus, _stPR2000_TunnFactor*pstTunnFactor,
                           _stPR2000_MeasureEqInfo*pstMeasureEqInfo)
{
    int result = -1;
    _stPR2000_Reg stReg;
    uint8_t u8RegData;
    uint8_t u8RegMask;
    uint8_t vadcGain = 0;
    if((pstVidStatusReg == NULL
       ) || (pstDetGainStatus == NULL) || (pstTunnFactor == NULL) || (pstMeasureEqInfo == NULL))
    {
        ErrorString("\x69\x6e\x76\x61\x6c\x69\x64\x20\x61\x72\x67\x75" "\n");
        return(
                  result);
    }
    stReg.reg = 0x0011;
    u8RegMask = 0x70;
    u8RegData = 0;
    if((result =
            PR2000_PageReadMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, &
                                   u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x72\x65\x61\x64" "\n");
        return(result);
    }
    vadcGain = (u8RegData >> 4) & 0x7;
    if(pstTunnFactor->stepDir > 0)
    {
        if(vadcGain < 0x7)
        {
            vadcGain++;
        }
        else
        {
            return(0);
        }
    }
    else
    {
        if(vadcGain > 0)
        {
            vadcGain--;
        }
        else
        {
            return(0);
        }
    }
    pstMeasureEqInfo->vadcGain = vadcGain;
    Print(
        "\x25\x78\x2d\x53\x65\x74\x20\x54\x75\x6e\x6e\x20\x56\x61\x64\x63\x3a\x30\x78\x25\x78" "\n"
        , slvAddr COMMA pstMeasureEqInfo->vadcGain);
    stReg.reg = 0x0011;
    u8RegMask = 0x70;
    u8RegData = (pstMeasureEqInfo->vadcGain & 0x7) << 4;
    if((result = PR2000_PageWriteMaskBit
                 (i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
        ;
        return(result);
    }
    result = 1;
    return(result);
}
int PR2000_SetTunnEQBand(const int
                         i2cFd, const uint8_t slvAddr, _stPR2000_VidStatusReg*pstVidStatusReg, const
                         _stPR2000_DetGainStatus*pstDetGainStatus, _stPR2000_TunnFactor*pstTunnFactor,
                         _stPR2000_MeasureEqInfo*pstMeasureEqInfo)
{
    int result = -1;
    _stPR2000_Reg stReg;
    uint8_t u8RegData;
    uint8_t u8RegMask;
    uint8_t vadcEqBand = 0;
    if((pstVidStatusReg ==
        NULL) || (pstDetGainStatus == NULL) || (pstTunnFactor == NULL) || (pstMeasureEqInfo == NULL)
      )
    {
        ErrorString("\x69\x6e\x76\x61\x6c\x69\x64\x20\x61\x72\x67\x75" "\n");
        return(
                  result);
    }
    stReg.reg = 0x0013;
    u8RegMask = 0x37;
    u8RegData = 0;
    if((result =
            PR2000_PageReadMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask, &
                                   u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
        ;
        return(result);
    }
    vadcEqBand = (u8RegData & 0x7) | ((u8RegData & 0x30) >> 1);
    if(
        pstTunnFactor->stepDir > 0)
    {
        if(vadcEqBand < 0x1f)
        {
            vadcEqBand++;
        }
        else
        {
            return(0);
        }
    }
    else
    {
        if(vadcEqBand > 0)
        {
            vadcEqBand--;
        }
        else
        {
            return(0);
        }
    }
    pstMeasureEqInfo->vadcEqBand = vadcEqBand;
    Print(
        "\x25\x78\x2d\x53\x65\x74\x20\x54\x75\x6e\x6e\x20\x76\x61\x64\x63\x45\x71\x42\x61\x6e\x64\x3a\x30\x78\x25\x78" "\n"
        , slvAddr COMMA pstMeasureEqInfo->vadcEqBand);
    stReg.reg = 0x0013;
    u8RegMask = 0x37;
    u8RegData = (vadcEqBand & 0x7) | (((vadcEqBand & 0x18) << 1) & 0x30);
    if((result =
            PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegMask,
                                    u8RegData)) < 0)
    {
        ErrorString(
            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
        ;
        return(result);
    }
    result = 1;
    return(result);
}
#endif
int PR2000_SetTblBrief(const int i2cFd, const uint8_t slvAddr, const enum
                              _eCameraStandard cameraStandard, const enum _eVideoResolution videoResolution,
                              const uint8_t regMode, _stJobProc*pstJobProc)
{
    int result = -1;
    int regInx = 0;
    _stPR2000_Reg stReg;
    uint8_t u8RegData = 0;
    uint8_t u8RegMask;
    const
    _stPR2000_Table_STD_HDResolution*pTblSTDHDResolution = NULL;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(\
SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
    const _stPR2000_Table_EXT_HDResolution*pTblEXTHDResolution = NULL;
#endif
    const _stPR2000_Table_SDResolution*pTblSDResolution = NULL;
    Dbg(
        "\x25\x78\x2d\x53\x65\x74\x54\x62\x6c\x42\x72\x69\x65\x66" "\n", slvAddr);
    pstJobProc->defChromaPhase = 0;
    regInx = 0;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(\
SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
    if(videoResolution > video_1920x1080p25)
    {
        switch(cameraStandard)
        {
            case SD:
            {
                pTblSDResolution = (const _stPR2000_Table_SDResolution*)stPR2000_Table_SDResol;
            }
            break;
#if defined(SUPPORT_STD_PVI)
            case PVI:
            {
                pTblEXTHDResolution = (const _stPR2000_Table_EXT_HDResolution*)
                                      stPR2000_Table_EXT_PVIResol;
            }
            break;
#endif
#if defined(SUPPORT_STD_HDA)
            case HDA:
            {
                pTblEXTHDResolution = (const _stPR2000_Table_EXT_HDResolution*)
                                      stPR2000_Table_EXT_HDAResol;
            }
            break;
#endif
#if defined(SUPPORT_STD_CVI)
            case CVI:
            {
                pTblEXTHDResolution = (const _stPR2000_Table_EXT_HDResolution*)
                                      stPR2000_Table_EXT_CVIResol;
            }
            break;
#endif
#if defined(SUPPORT_STD_HDT)
            case HDT_OLD:
            {
                pTblEXTHDResolution = (const _stPR2000_Table_EXT_HDResolution*)
                                      stPR2000_Table_EXT_HDT_OLDResol;
            }
            break;
            case HDT_NEW:
            {
                pTblEXTHDResolution = (const
                                       _stPR2000_Table_EXT_HDResolution*)stPR2000_Table_EXT_HDT_NEWResol;
            }
            break;
#endif
            default:
            {
                Error(
                    "\x49\x6e\x76\x61\x6c\x69\x64\x20\x63\x61\x6d\x65\x72\x61\x20\x53\x74\x61\x6e\x64\x61\x72\x64\x28\x25\x64\x29" "\n"
                    , cameraStandard);
                return(result);
            }
        }
    }
    else
    {
        switch(cameraStandard)
        {
            case SD:
            {
                pTblSDResolution = (const _stPR2000_Table_SDResolution*)stPR2000_Table_SDResol;
            }
            break;
#if defined(SUPPORT_STD_PVI)
            case PVI:
            {
                pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution*)
                                      stPR2000_Table_STD_PVIResol;
            }
            break;
#endif
#if defined(SUPPORT_STD_HDA)
            case HDA:
            {
                pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution*)
                                      stPR2000_Table_STD_HDAResol;
            }
            break;
#endif
#if defined(SUPPORT_STD_CVI)
            case CVI:
            {
                pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution*)
                                      stPR2000_Table_STD_CVIResol;
            }
            break;
#endif
#if defined(SUPPORT_STD_HDT)
            case HDT_OLD:
            {
                pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution*)
                                      stPR2000_Table_STD_HDT_OLDResol;
            }
            break;
            case HDT_NEW:
            {
                pTblSTDHDResolution = (const
                                       _stPR2000_Table_STD_HDResolution*)stPR2000_Table_STD_HDT_NEWResol;
            }
            break;
#endif
            default:
            {
                Error(
                    "\x49\x6e\x76\x61\x6c\x69\x64\x20\x63\x61\x6d\x65\x72\x61\x20\x53\x74\x61\x6e\x64\x61\x72\x64\x28\x25\x64\x29" "\n"
                    , cameraStandard);
                return(result);
            }
        }
    }
#else
    switch(cameraStandard)
    {
        case SD:
        {
            pTblSDResolution = (const
                                _stPR2000_Table_SDResolution*)stPR2000_Table_SDResol;
        }
        break;
#if defined(SUPPORT_STD_PVI)
        case PVI:
        {
            pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution*)
                                  stPR2000_Table_STD_PVIResol;
        }
        break;
#endif
#if defined(SUPPORT_STD_HDA)
        case HDA:
        {
            pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution*)
                                  stPR2000_Table_STD_HDAResol;
        }
        break;
#endif
#if defined(SUPPORT_STD_CVI)
        case CVI:
        {
            pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution*)
                                  stPR2000_Table_STD_CVIResol;
        }
        break;
#endif
#if defined(SUPPORT_STD_HDT)
        case HDT_OLD:
        {
            pTblSTDHDResolution = (const _stPR2000_Table_STD_HDResolution*)
                                  stPR2000_Table_STD_HDT_OLDResol;
        }
        break;
        case HDT_NEW:
        {
            pTblSTDHDResolution = (const
                                   _stPR2000_Table_STD_HDResolution*)stPR2000_Table_STD_HDT_NEWResol;
        }
        break;
#endif
        default:
        {
            Error(
                "\x49\x6e\x76\x61\x6c\x69\x64\x20\x63\x61\x6d\x65\x72\x61\x20\x53\x74\x61\x6e\x64\x61\x72\x64\x28\x25\x64\x29" "\n"
                , cameraStandard);
            return(result);
        }
    }
#endif
    if((videoResolution <= video_960x576i50))
    {
        stReg.reg = pTblSDResolution[regInx].stReg
                    .reg;
    }
    else if((video_1280x720p60 <= videoResolution) && (videoResolution <=
            video_1920x1080p25))
    {
        stReg.reg = pTblSTDHDResolution[regInx].stReg.reg;
    }
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
    else if((video_1280x800p60 <= videoResolution) && (videoResolution <=
            video_1280x800p25))
    {
        stReg.reg = pTblEXTHDResolution[regInx].stReg.reg;
    }
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
    else if((video_1280x960p60 <= videoResolution) && (videoResolution <=
            video_1280x960p25))
    {
        stReg.reg = pTblEXTHDResolution[regInx].stReg.reg;
    }
#endif
    while(stReg.reg != 0xffff)
    {
        if((videoResolution <= video_960x576i50))
        {
            u8RegData =
                pTblSDResolution[regInx].u8Data[videoResolution];
        }
        else if((video_1280x720p60 <=
                 videoResolution) && (videoResolution <= video_1920x1080p25))
        {
            u8RegData =
                pTblSTDHDResolution[regInx].u8Data[videoResolution - video_1280x720p60];
        }
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
        else if((video_1280x800p60 <= videoResolution) && (videoResolution <=
                video_1280x800p25))
        {
            u8RegData = pTblEXTHDResolution[regInx].u8Data[videoResolution
                        - video_1280x800p60];
        }
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
        else if((video_1280x960p60 <= videoResolution) && (videoResolution <=
                video_1280x960p25))
        {
            u8RegData = pTblEXTHDResolution[regInx].u8Data[videoResolution
                        - video_1280x960p60];
        }
#endif
        if(stReg.reg == 0x0146)
        {
            pstJobProc->defChromaPhase |= (uint32_t)(u8RegData & 0x1f) << 16
                                          ;
        }
        else if(stReg.reg == 0x0147)
        {
            pstJobProc->defChromaPhase |= (uint32_t)(u8RegData &
                                          0xff) << 8;
        }
        else if(stReg.reg == 0x0148)
        {
            pstJobProc->defChromaPhase |= (uint32_t)(
                                              u8RegData & 0xff);
        }
        if(regMode == 0)
        {
            if(((0x0010 <= stReg.reg) && (stReg.reg <= 0x0013)) || ((0x00e0 == stReg.reg)) || ((0x0111
                    <= stReg.reg) && (stReg.reg <= 0x011f)) || ((0x0131 <= stReg.reg) && (stReg.reg <= 0x0138)) ||
               ((0x013a == stReg.reg)) || ((0x013d <= stReg.reg) && (stReg.reg <= 0x014c)))
            {
                if(stReg.reg
                   == 0x00e0)
                {
                    u8RegMask = 0x0f;
                    if((result = PR2000_PageWriteMaskBit(i2cFd, slvAddr, stReg.
                                                         b.page, stReg.b.addr, u8RegMask, u8RegData)) < 0)
                    {
                        ErrorString(
                            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                        ;
                        return(result);
                    }
                }
                else
                {
                    Dbg(
                        "\x69\x6e\x78\x3a\x25\x64\x2c\x20\x70\x61\x67\x65\x3a\x25\x64\x2c\x20\x72\x65\x67\x3a\x30\x78\x25\x30\x32\x78\x2c\x20\x64\x61\x74\x61\x3a\x30\x78\x25\x30\x32\x78" "\n"
                        , regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);
                    if((result =
                            PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                    {
                        ErrorString(
                            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                        ;
                        return(result);
                    }
                }
            }
        }
        else if(regMode == 1)
        {
            if(((0x0117 <= stReg.reg) && (stReg.reg <= 0x011e)) || ((0x0146 <= stReg.reg) && (stReg.reg
                    <= 0x0148)))
            {
                if(cameraStandard == HDA)
                {
                    if(videoResolution == video_1280x720p60)
                    {
                        if(0x0146 == stReg.
                           reg)
                        {
                            u8RegData = 0x64;
                        }
                        else if(0x0147 == stReg.reg)
                        {
                            u8RegData = 0xef;
                        }
                        else if(0x0148 ==
                                stReg.reg)
                        {
                            u8RegData = 0x8e;
                        }
                    }
                    else if(videoResolution == video_1280x720p50)
                    {
                        if(
                            0x0146 == stReg.reg)
                        {
                            u8RegData = 0x64;
                        }
                        else if(0x0147 == stReg.reg)
                        {
                            u8RegData = 0xef;
                        }
                        else if(0x0148 == stReg.reg)
                        {
                            u8RegData = 0xf8;
                        }
                    }
                }
                if(0x0146 == stReg.reg)
                {
                    u8RegData |=
                        0x20;
                }
                Dbg(
                    "\x69\x6e\x78\x3a\x25\x64\x2c\x20\x70\x61\x67\x65\x3a\x25\x64\x2c\x20\x72\x65\x67\x3a\x30\x78\x25\x30\x32\x78\x2c\x20\x64\x61\x74\x61\x3a\x30\x78\x25\x30\x32\x78" "\n"
                    , regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);
                if((result =
                        PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                {
                    ErrorString(
                        "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                    ;
                    return(result);
                }
            }
        }
        else if(regMode == 2)
        {
            if(((0x0111 == stReg.reg) || (stReg.reg == 0x0113)) || ((0x0129 <= stReg.reg) && (stReg.reg
                    <= 0x012a)))
            {
                Dbg(
                    "\x69\x6e\x78\x3a\x25\x64\x2c\x20\x70\x61\x67\x65\x3a\x25\x64\x2c\x20\x72\x65\x67\x3a\x30\x78\x25\x30\x32\x78\x2c\x20\x64\x61\x74\x61\x3a\x30\x78\x25\x30\x32\x78" "\n"
                    , regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);
                if((result =
                        PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                {
                    ErrorString(
                        "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                    ;
                    return(result);
                }
            }
        }
        regInx++;
        if((videoResolution <= video_960x576i50))
        {
            stReg.reg =
                pTblSDResolution[regInx].stReg.reg;
        }
        else if((video_1280x720p60 <= videoResolution)
                && (videoResolution <= video_1920x1080p25))
        {
            stReg.reg = pTblSTDHDResolution[regInx].
                        stReg.reg;
        }
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
        else if((video_1280x800p60 <= videoResolution) && (videoResolution <=
                video_1280x800p25))
        {
            stReg.reg = pTblEXTHDResolution[regInx].stReg.reg;
        }
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
        else if((video_1280x960p60 <= videoResolution) && (videoResolution <=
                video_1280x960p25))
        {
            stReg.reg = pTblEXTHDResolution[regInx].stReg.reg;
        }
#endif
    }
    {
        stReg.reg = 0x0154;
        u8RegData = 0x0e;
        if((result = PR2000_PageWrite(i2cFd, slvAddr,
                                      stReg.b.page, stReg.b.addr, u8RegData)) < 0)
        {
            ErrorString(
                "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
            ;
            return(result);
        }
        stReg.reg = 0x0154;
        u8RegData = 0x0f;
        if((result = PR2000_PageWrite(
                         i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
        {
            ErrorString(
                "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
            ;
            return(result);
        }
    }
    return(result);
}


